JComboBox 클래스

✒️ 2025-05-15 14:37 내용 수정



텍스트 필드와 풀다운 리스트를 조합한 형태를 제공하는 클래스

JComboBox<T> 인스턴스이름 = new JComboBox<>();
오버로드된 다른 생성자
JComboBox<>(E[] items)
JComboBox<>(ComboBoxModel<E> aModel)
JComboBox<>(Vector<E> items)
메서드 설명
setBounds(int a, int b) x=a, y=b 크기의 ComboBox 설정
addActionListener(ActionListener l) ActionListener를 추가
removeActionListener(ActionListener l) ActionListener를 제거
removeItem(int index) ComboBox에 추가되었던 인덱스 index 위치의 아이템 제거(기본 데이터 모델에서만 작동)
removeItem(Object o) ComboBox에 추가되었던 Object 제거(기본 데이터 모델에서만 작동)
removeAllItems() 모든 아이템을 제거(기본 데이터 모델에서만 작동)
insertItemAt(Object o, int index) 인덱스 index 위치에 Object 추가(기본 데이터 모델에서만 작동)
addItem(E item) 아이템 리스트에 아이템을 추가(기본 데이터 모델에서만 작동)
setSelectedItem(Object anObject) JComboBox에서 선택된 아이템을 디스플레이 영역에서 전달 받은 Object로 설정
Object getSelectedItem() 선택된 아이템을 반환
Object getSelectedIndex() 주어진 아이템과 일치하는 리스트에서 첫 번째 아이템을 반환